<template>
      <div id="app">
        <nav>
                <label for="title">ToDoLis</label>
                <input type="text" v-model="text" v-mykey="add" @keyup.enter="add"  class="input" id="title" placeholder="添加to do">
                <!-- <input type="button" value="添加"  @click="add"> -->
        </nav>
         
                <h2 >
                    正在进行 
                    <span id="todocount"></span>
                </h2>
                <!-- 正在进行的任务 -->
                <ol  id="todolist" class="demo-box">
                    <!-- 遍历 todolist 进行添加 -->
                    <li v-for="(item,index) in todolist" :key="index">
                        <input v-if="checked" @click="okAdd(index)" type="checkbox">
                        {{item}}
                         <a href="javascript:void(0)" @click="remove(index)" :key="index">-</a>
                    </li>
                </ol>

                <h2 >
                    已经完成 
                    <span id="todocount">0</span>

                </h2>
                <!-- 已完成的任务 -->
                <ol  id="todolist" class="demo-box">
                    <!-- 遍历 newlist 进行添加 -->
                    <li v-for="(item,index) in newlist"  :value="item" :key="index">
                        <!-- <input v-if="checked" type="checkbox"> -->
                        {{item}}
                         <a href="javascript:void(0)" @click="okremove(index)" :key="index">-</a>
                    </li>
                </ol>

    </div>

</template>
<script>

export default{
  name:"Home",
  data (){
    return{
      todolist: [],
      newlist : [],
      text : "",
      checked : true
    };
  },
    methods:{
      add(){ //未完成任务添加
      this.todolist.push(this.text)
        this.text = ""
      },
      remove(index){ //未完成任务移除
      this.todolist.splice(index,1)
      },
      okAdd(index){ //已完成添加
      if(this.checked){
      //如果 tolist的单选框选中 就添加到 newList
      this.newlist.push(this.todolist[index])
      //删除 tolist的任务
      this.todolist.splice(index,1);
        }
      },
      okremove(index){ //已完成移除
      this.newlist.splice(index,1)
      }
    },
    directives:{
    //键盘事件
    mykey:{
    inserted(el){
    if(el.keyCode === 13){
    this.add()
      }
                       
    }
  }
 }
}
</script>

<style lang="scss" scoped>
nav{
  width: 100%;
  height: 60px;
  background-color: rgba(0,0,0,0.8);
  display: flex;
  justify-content: center;
  align-items:center;

  h2{
    color: white;
  }
  input{
    margin-left: 30px;
    width: 400px;
    height: 30px;
    border: 0;
    border-radius: 5px;
  }
  label{
    color: #ddd;
  }
}

ol{
  list-style: none;
  li span{
    width: 150px;
    display: inline-block;
    text-align: left;
  }
}
/* *{
  margin: 0;
  padding: 0;
}
body{
  font-size: 16px;
  background: #cdcdcd;
  font-family: "Helvetica Neue",Arial, Helvetica, sans-serif;
}
.top{
  height: 50px;
  background: rgba(47, 47, 47, 0.98);
}
.center{
  max-width: 620px;
  margin: 0 auto;
  padding: 0 10px;
}
label{
  float:left;
  width: 50px;
  line-height: 50px;
  color: #ddd;
  font-size: 24px;
  cursor: pointer;
}
.top input{
  float: right;
  width: 60%;
  height: 24px;
  margin-top: 12px;
  text-indent: 10px;
  border-top-left-radius: 5px;
  border-radius: 5px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.24),0 1px 6px rgba(0,0,0, 0.45);
  outline: none;
  border: none;
}
h2{
  position: relative;
  margin: 26px 0;
}
h2.todocount{
  position:absolute;
  top: 2px;
  right: 5px;
  display: inline-block;
  padding: 0 5px;
  height: 20px;
  border-radius: 20px;
  background: #e6e6fa;
  line-height: 22px;
  text-align: center;
  color: #666;
  font-size: 14px;
}
ol{
  margin: 28px 0 32px;
}
li{
  height: 32px;
  line-height: 32px;
  background: #fff;
  position: relative;
  margin-bottom: 10px;
  padding: 0 48px;
  border-radius: 3px;
  border-left: 5px solid #629a9c;
  box-shadow: 0 1px 2px rgba(0,0,0, 0.07);
}
li input{
  position: absolute;
  top: 6px;
  left: 22px;
  width: 22px;
  height: 22px;
  cursor: pointer;
}
li p{
  line-height: 34px;
}
li a{
  position: absolute;
  top: 4px;
  right: 5px;
  display: inline-block;
  width: 14px;
  height: 12px;
  border-radius: 14px;
  border: 6px double #fff;
  background: #ccc;
  line-height: 12px;
  text-align: center;
  color: #fff;
  font-weight: bold;
  font-size: 14px;
  cursor: pointer;
} */

</style>
